clear; clc;
N_newline = 10;
N = input("点数? ");
dac_bits = input("DAC位数? ");

func_triangle = @(t)tripuls(t-pi, 2*pi);
func_sine = @(t)(sin(t)+1)/2;
func_rect = @(t)(t>=pi);

FUNC = func_rect;

t = linspace(0, 2*pi, N);
y = floor(FUNC(t) * 2.^dac_bits);

tableStr = "const unsigned int N_sine_table = " + int2str(N) + ";" + ...
    newline + "uint16_t sine_table[N_sine_table] = \" + newline;

tableStr = tableStr + nums_to_c_array_str(y, N_newline, "%d");
tableStr = tableStr + ";";

disp(tableStr);

plot(t, y);